# 使用官方的 Python 基础镜像
FROM python:3.10-slim AS base

WORKDIR /app

# 清空所有 sources.list.d 下的文件，确保不会使用官方 bookworm 源
RUN rm -rf /etc/apt/sources.list.d/*

# 覆盖sources.list为阿里云Debian bullseye源
RUN echo "deb http://mirrors.aliyun.com/debian bullseye main contrib non-free\n\
deb http://mirrors.aliyun.com/debian-security bullseye-security main contrib non-free\n\
deb http://mirrors.aliyun.com/debian bullseye-updates main contrib non-free\n" > /etc/apt/sources.list && \
    apt-get update && apt-get install -y --no-install-recommends supervisor && \
    rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

RUN mkdir -p log data conf
COPY biz ./biz
COPY api.py ./api.py
COPY ui.py ./ui.py
COPY conf/prompt_templates.yml ./conf/prompt_templates.yml

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

FROM base AS app
COPY conf/supervisord.app.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 5001 5002

FROM base AS worker
COPY ./conf/supervisord.worker.conf /etc/supervisor/conf.d/supervisord.conf
